<template>
    <div class="twoAdd">
        <el-row>
            <el-col :span="24">one添加</el-col>
        </el-row>
        <el-form ref="form" :model="form" label-width="130px" style="margin-top:30px;">
            <el-form-item label="姓名（必填）">
                <el-input v-model="form.name" style="width:360px;"></el-input>
            </el-form-item>
            <el-form-item label="电话（必填）">
                <el-input v-model="form.mobile" style="width:360px;"></el-input>
            </el-form-item>
            <el-form-item label="密码（必填）">
                <el-input v-model="form.password" style="width:360px;"></el-input>
            </el-form-item>
            <el-form-item label="确认密码（必填）">
                <el-input v-model="form.password_confirm" style="width:360px;"></el-input>
            </el-form-item>
            <el-form-item label="状态（必填）">
                <el-select v-model="form.status" placeholder="请选择状态">
                    <el-option v-for="(item, key) in stats" :value="key" :key="key" :label="item"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">添加保存</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    import axios from 'axios'
    export default {
        name: "addshangpin",
        data() {
            return {
                form: {
                    name: '',
                    mobile: '',
                    password: '',
                    password_confirm:'',
                    status:'',
                },
                stats: { "1": '正常', "-1": '禁用' },
            }
        },
        methods: {
            //提交
            onSubmit() {
                let parames = {
                    method: 'post',
                    url: this.$store.state.baseurl + 'admin/admin/add',
                    parameObj: {
                        name: this.form.name,
                        mobile: this.form.mobile,
                        status:this.form.status,
                        password:this.form.password,
                        password_confirm:this.form.password_confirm
                    }
                }
                this.$store.dispatch('fetch', parames)
                .then(res => {
                    console.log(res);
                    if(res.code===200){
                        console.log('11111111111')
                        alert(res.message)
                        this.form.name='';
                        this.form.mobile='';
                        this.form.status='';
                        this.form.password='';
                        this.form.password_confirm='';
                    }
                })
                .catch(err => {
                    console.log(err)
                    console.log('222222222222222')
                })
            },
        }
    }
</script>
<style scoped>
</style>